package com.mall.file.file;

import org.javaswift.joss.model.Container;
import org.javaswift.joss.model.StoredObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collection;

/**
 * @author Darren
 * @date 2022-07-29 17:41
 * Description：
 */
@Component
public class FileHandler {
    @Autowired
    private Container container;

    /**
     * 文件上传
     * @param filename 文件名
     * @param buffer 文件的byte数组
     */
    public void upload(String filename, byte[] buffer) {
        // 获取容器
        StoredObject object = container.getObject(filename);
        // 上传
        object.uploadObject(buffer);
    }

    public byte[] download(String filename) {
        // 获取容器
        StoredObject object = container.getObject(filename);
        // 下载
        return object.downloadObject();
    }
}
